package com.yc.tomcat.impl;


import com.yc.tomcat.HttpServletRequest;
import com.yc.tomcat.HttpServletResponse;
import com.yc.tomcat.ServletException;

import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("post.s")
public class PostServlet extends HttpServletImpl{
    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
        PrintWriter out=response.getWriter();
        response.setContentType("text/html;charset=utf-8");
        String a = request.getParameter("a");
        String b = request.getParameter("b");
        String op = request.getParameter("op");
        int result=0;
        if("1".equals(op)){
            result=Integer.parseInt(a)+Integer.parseInt(b);
            op="+";
        }else if ("2".equals(op)){
            result=Integer.parseInt(a)-Integer.parseInt(b);
            op="-";
        }
        out.println(String.format("%s %s %s = %d",a,op,b,result));
    }
}
